package screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldStyle;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;

import com.me.mygdxgame.Gamedoan;

public class MenuScreen implements Screen {
	Table table;
	Gamedoan myGame;
	TextButton startGameButton;
	TextButton optionButton;
	TextButton exit;
	TextButtonStyle buttonStyle;
	Stage stage;
	Skin skin;
	TextureAtlas atlas;
	SpriteBatch spriteBatch;
	Texture texture;
	static float BUTTON_WIDTH =300f;
	static float BUTTON_HEIGHT =50f;
	public MenuScreen (Gamedoan Game){
		myGame=Game;
		
		table = new Table();
		stage = new Stage();
		skin = new Skin();
		atlas= new TextureAtlas(Gdx.files.internal("button/textures.pack"));
		skin.addRegions(atlas);
		Gdx.input.setInputProcessor(stage);
		buttonStyle= new TextButtonStyle();
		buttonStyle.font = new BitmapFont();
	    buttonStyle.fontColor = Color.YELLOW;
	    buttonStyle.pressedOffsetY = 1f;
	    buttonStyle.downFontColor = new Color(0.8f, 0.8f, 0.8f, 1f);
	    buttonStyle.up = skin.getDrawable("buttonup");
	    buttonStyle.down=skin.getDrawable("buttondown");
	    
	    /*textFieleStyle= new TextFieldStyle();
	  
	    
	    gamedoan= new TextField("GAMEDOAN", skin);*/
	    spriteBatch = new SpriteBatch();
		texture = new Texture (Gdx.files.internal("background/gamedoan.png"));
		
	    
	    //add button start
		startGameButton= new TextButton("Start Game", buttonStyle);
		startGameButton.setWidth(BUTTON_WIDTH);
		startGameButton.setHeight(BUTTON_HEIGHT);
		
		startGameButton.addListener(new ClickListener(){
			@Override
			public void clicked(InputEvent event, float x, float y){
				myGame.setScreen(myGame.getSplashSceen());
			}
		});
		table.row();
		table.add(startGameButton).width(BUTTON_WIDTH);
		
		//add button option
		optionButton= new TextButton("Option", buttonStyle);
		optionButton.addListener(new ClickListener(){
			@Override
			public void clicked(InputEvent event, float x, float y){
				myGame.setScreen(myGame.getOptionScreen());
			}
		});
		table.row();
		table.add(optionButton).width(BUTTON_WIDTH);
		//add button exit
		exit= new TextButton("Exit Game", buttonStyle);
		exit.addListener(new ClickListener(){
			@Override
			public void clicked(InputEvent event, float x, float y){
				myGame.dispose();
				Gdx.app.exit();
				System.exit(1);
			}
		});
		table.row();
		//table.align(20);
		table.add(exit).width(BUTTON_WIDTH);
		
		//table.setFillParent(true);
	
	
		
		stage.addActor(table);
		
	}
	@Override
	public void render(float delta) {
		// TODO Auto-generated method stub
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		    Gdx.gl.glClearColor(0, 0, 0, 1);
		    spriteBatch.begin();
		    spriteBatch.draw(texture, Gdx.app.getGraphics().getWidth()/2- texture.getWidth()/2,Gdx.app.getGraphics().getHeight()-texture.getHeight()-20);
		    spriteBatch.end();
		    stage.act(Gdx.graphics.getDeltaTime());
		    stage.draw();
		    
	}

	@Override
	public void resize(int width, int height) {
		// TODO Auto-generated method stub
		table.setX(width/2f);
		table.setY(height/2f);
	}

	@Override
	public void show() {
		// TODO Auto-generated method stub
		Gdx.input.setInputProcessor(stage);
	}

	@Override
	public void hide() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		
	}

}
